home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <ctype.h>
- #include "dirscan.h"
-
- char path [_MAX_DIR];
- char drive [_MAX_DRIVE];
- char fn [_MAX_FNAME];
- char ext [_MAX_EXT];
- char file_id [_MAX_FNAME+_MAX_EXT-1];
- char cur_path[_MAX_DIR];
- char displayed;
-
- long num_files=0, num_dirs=0, num_found=0;
-
- void display_dir(char[]);
- void display_file(char[],struct find_t);
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
-
- char dpath[_MAX_PATH];
- int rc;
-
- if (argc < 2)
- {
- fprintf(stderr,"No filename specified\n");
- exit(1);
- }
-
- /* parse the first argument */
-
- _splitpath(argv[1],drive,path,fn,ext);
-
- if (drive[0] == '\0') /* drive not specified */
- {
-
- /* use the currently logged drive */
-
- unsigned dnum;
- _dos_getdrive(&dnum);
- drive[0] = * ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"+dnum-1);
- drive[1] = ':';
- drive[2] = '\0';
-
- }
- else /* drive specified */
- {
-
- /* make sure it's valid */
-
- if (strlen(drive) != 2 || !isalpha(drive[0]) || drive[1] != ':')
- {
- fprintf(stderr,"Invalid drive specification\n");
- exit (-1);
- }
-
- }
-
- if (path[0] == '\0') /* if path is null, set it to '\' */
- {
- path[0] = '\\';
- path[1] = '\0';
- }
-
- if (fn[0] == '\0') /* if filename is null, set it to '*' */
- {
- fn[0] = '*';
- fn[1] = '\0';
- }
-
- if (ext[0] == '\0') /* if extension is null, set it to '*' */
- {
- ext[0] = '.';
- ext[1] = '*';
- ext[2] = '\0';
- }
-
- /* build current path and filename.ext strings */
-
- strcpy(dpath,drive);
- strcat(dpath,path);
- strupr(dpath);
-
- strcpy(file_id,fn);
- strcat(file_id,ext);
- strupr(file_id);
-
- /* clear screen and display initialization message */
-
- system("CLS");
- printf("Searching for %s%s\n",dpath,file_id);
-
- /* invoke "dirscan" search routine */
-
- num_files = dirscan(dpath, /* Initial Path */
- file_id, /* File Name Mask */
- _A_NORMAL, /* File Attribute Mask */
- display_dir, /* Directory Routine */
- display_file); /* File Routine */
-
- printf("\n%8ld files found",num_found);
- printf("%8ld directories searched",num_dirs);
- printf("%8ld files examined\n",num_files);
-
- exit(0);
- }
-
-
- void display_dir(path)
- char path[];
- {
-
- strcpy(cur_path,path);
- displayed = 0;
- num_dirs++;
-
- }
-
- void display_file(path,buffer)
- char path[];
- struct find_t buffer;
- {
-
- FILE_TIME *time = (FILE_TIME *) &buffer.wr_time;
- FILE_DATE *date = (FILE_DATE *) &buffer.wr_date;
-
- num_found++;
-
- if (!displayed)
- {
- printf("%s\n",cur_path);
- displayed = 1;
- }
-
- printf(" %-12s %9ld",buffer.name,buffer.size);
- printf(" %2.2d:%2.2d:%2.2d",time->hour,
- time->minute,
- time->second*2);
- printf(" %2.2d/%2.2d/%4.4d\n",date->month,
- date->day,
- date->year+1980);
-
- }